{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
		</div>
	</form>
	<table class="layui-hide" id="shoufei" lay-filter="shoufei"></table>
</div>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加收费表">+ 首次缴费</span>
	</div>
</script>

<script type="text/html" id="barDemo">
<div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">续费</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table,tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#shoufei',
			title: '收费表列表',
			toolbar: '#toolbarDemo',
			url: '/admin/shoufei/datalist',
			page: true,
			limit: 20,
			cellMinWidth: 40,
			cols: [
				[
				{
					fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 30
				},{
					field: 'name',
					title: '学生姓名',
					align: 'center',
					templet: function (d) {
						if(d.chongzhi==1){
							//var html = '<i style="color:red">是</i>';
							var html = d.name+'&nbsp;<span class="layui-badge layui-bg-orange">首</span>';
						}else{
							var html = d.name+'&nbsp;<span class="layui-badge layui-bg-green">续</span>';
						}
						
						return html;
					}
				},{
					field: 'money',
					title: '缴费金额',
					align: 'center'
				},{
					field: 'jiaofei_time',
					title: '缴费时间',
					align: 'center'
				},{
					field: 'start_time',
					title: '开始时间',
					align: 'center'
				},{
					field: 'end_time',
					title: '结束时间',
					align: 'center'
				},{
					field: 'type_id',
					title: '类型',
					align: 'center'
				},{
					field: 'shichang_id',
					title: '时长',
					align: 'center'
				},{
					field: 'baohan',
					title: '包含项目',
					align: 'left',
					width: 136,
					templet: function (d) {
						//alert(d.baohan[0]);
						let baohanCount  = d.baohan.length;
						//alert(baohanCount);
						if(baohanCount>0){
							var html='';
							for(let i=0;i<baohanCount;i++){
								html += '<span class="layui-badge">'+d.baohan[i]+'</span>'
							}
						}
						
						return html;
					}
				},{
					field: 'neirong',
					title: '内容',
					align: 'center'
				},{
					field: 'yuanyin',
					title: '原因',
					align: 'center'
				},{
					field: 'remark',
					title: '备注',
					align: 'center'
				},
				{
					fixed: 'right',
					field: 'right',
					title: '操作',
					toolbar: '#barDemo',
					width: 136,
					align: 'center'
				}				
				]
			]
		});
		
		//监听表头工具栏事件
		table.on('toolbar(shoufei)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/shoufei/add");
				return false;
			}
		});

		//监听表格行工具事件
		table.on('tool(shoufei)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/shoufei/xufei?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/shoufei/edit?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/shoufei/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {

			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->